%Declare the symbolic variables (syms)
syms PbVal PbLeadVal RVal 
f= -Pb*exp(PbVal) + (1+rho * Pb*exp(PbLeadVal)) / (R*exp(RVal));

%Take symbolic derivatives
dd1 = diff(f,PbVal);
dd2 = diff(f,PbLeadVal);
dd3=diff(f,RVal);

%Evaluates symbolic derivatives

PbVal=0;  %loglin
PbLeadVal=0;  %loglin
RVal=0;


D1=subs(dd1);
D2=subs(dd2);
D3=subs(dd3);

% Transform symbolic into numbers (with double precision)
d1=double(D1);
d2=double(D2);
d3=double(D3);

ACont(ii,pbcLog)        = d1;
ALead(ii,pbcLog)       = d2;
ACont(ii,RcLog)=d3;